package com.ng.desktop.view.dieta;

import java.util.HashMap;

import javax.swing.JOptionPane;

import com.ng.desktop.model.Receta;
import com.ng.desktop.persistence.RecetaPersistence;
import com.ng.desktop.view.receta.RecetaDialog;
import com.ng.framework.view.desktop.NGEntitySelectorField;

public class RecetaSelectorField extends NGEntitySelectorField<Receta, RecetaPersistence> {

	private static final long serialVersionUID = -9099299334828461372L;

	private Comida comida;
	private HashMap<Comida, Receta> recetasComidas;

	public RecetaSelectorField(HashMap<Comida, Receta> recetasComidas) {
		this.recetasComidas = recetasComidas;
	}

	@Override
	public void select() {
		RecetaDialog recetaDialog = new RecetaDialog(JOptionPane.getFrameForComponent(this), this);
		recetaDialog.setVisible(true);
	}

	@Override
	public void deselect() {
		super.deselect();
		this.recetasComidas.remove(this.comida);
	}

	@Override
	public void setEntity(Receta entity) {
		super.setEntity(entity);

		this.recetasComidas.put(this.comida, entity);
	}

	public void setComida(Comida comida) {
		this.comida = comida;
	}

	@Override
	public void edit() {
	}

}
